package com.ksm.zyz.controller;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ksm.zyz.common.base.BaseController;
import com.ksm.zyz.sys.entity.BaseGoodsInfo;
import com.ksm.zyz.sys.entity.BaseGoodsStock;
import com.ksm.zyz.sys.entity.BaseGoodsUnit;
import com.ksm.zyz.sys.entity.BsData;
import com.ksm.zyz.sys.entity.ExtData;
import com.ksm.zyz.sys.serverentity.sBaseGoodsInfo;
import com.ksm.zyz.sys.serverentity.sBaseGoodsStock;
import com.ksm.zyz.sys.serverentity.sBaseGoodsUnit;
import com.ksm.zyz.sys.serverservice.sBaseGoodsInfoService;
import com.ksm.zyz.sys.serverservice.sBaseGoodsStockService;
import com.ksm.zyz.sys.serverservice.sBaseGoodsUnitService;
import com.ksm.zyz.sys.service.baseGoodsInfoService;
import com.ksm.zyz.sys.service.baseGoodsStockService;
import com.ksm.zyz.sys.service.baseGoodsUnitService;

/**
 * @author liuhao
 *
 */
@Controller
@RequestMapping("BaseGoodsTongBu")
public class BaseGoodsController extends BaseController<sBaseGoodsInfo> {

	@Autowired
	private sBaseGoodsInfoService sService;
	@Autowired
	private baseGoodsInfoService Service;
	@Autowired
	private sBaseGoodsStockService sStockService;
	@Autowired
	private baseGoodsStockService StockService;
	@Autowired
	private sBaseGoodsUnitService sUnitService;
	@Autowired
	private baseGoodsUnitService UnitService;
	

	   @RequestMapping(value ="BaseGoodsInfo")
	    @ResponseBody
		public ExtData BaseSupplierInfo(int ming, HttpServletRequest req){
	         //List<sOrderGoodsInfo> list=sgoodsService.selectSome();
		   int scount=(int)sService.selectAllCount();
		   int count=(int)Service.selectCount(ming);
		   int begin=0;
		   if(scount>count)
		   {
			   
			   begin=count;
		   }
		   else{
			   extData.setTotalCount(0);
			   return extData;
		   }
		   System.out.println(scount+"总数据量");
			   sBaseGoodsInfo sInfo =new sBaseGoodsInfo();
			   BsData bsdata=new BsData();
			   bsdata.setBegin(begin);
			   bsdata.setLimit(scount);
			   sInfo.setBsData(bsdata);
			   List<BaseGoodsInfo> list=sService.selectAllInfo(sInfo);
			   for(int j=0;j<list.size();j++)
			   {
				   BaseGoodsInfo info=list.get(j);
				   System.out.println(list.get(j).getGoodsName());
				   info.setSmId(ming);			   				   
				  try
				   {
					   Service.insertSelective(info);					   
				   }
				   catch(Exception e){
					   System.out.println(info.getId()+"@@@@@");
					   extData.setTotalCount(j);
					   return extData;   
				   }
				   
			   }
			     			   
		   extData.setTotalCount(scount-count);	
	               
			return extData;    
		}
	   @RequestMapping(value ="BaseGoodsStock")
	    @ResponseBody
		public ExtData BaseSupplierStock(int ming, HttpServletRequest req){
	         //List<sOrderGoodsInfo> list=sgoodsService.selectSome();
		   int scount=(int)sStockService.selectAllCount();
		   int count=(int)StockService.selectCount(ming);
		   int begin=0;
		   if(scount>count)
		   {
			    begin=count;
		   }
		   else{
			   extData.setTotalCount(0);
			   return extData;
		   }
		   System.out.println(scount+"总数据量");
			   sBaseGoodsStock sInfo =new sBaseGoodsStock();
			   BsData bsdata=new BsData();
			   bsdata.setBegin(begin);
			   bsdata.setLimit(scount);
			   sInfo.setBsData(bsdata);
			   List<BaseGoodsStock> list=sStockService.selectAllInfo(sInfo);
			   for(int j=0;j<list.size();j++)
			   {
				   BaseGoodsStock info=list.get(j);
				   System.out.println(list.get(j).getStock());
				   info.setSmId(ming);			   				   
				  try
				   {
					  StockService.insertSelective(info);					   
				   }
				   catch(Exception e){
					   System.out.println(info.getId()+"@@@@@");
					   extData.setTotalCount(j);
					   return extData;   
				   }
				   
			   }
			     			   
		   extData.setTotalCount(scount-count);	
	               
			return extData;    
		}
	   @RequestMapping(value ="BaseGoodsUnit")
	    @ResponseBody
		public ExtData BaseSupplierUnit(int ming, HttpServletRequest req){
	         //List<sOrderGoodsInfo> list=sgoodsService.selectSome();
		   int scount=(int)sUnitService.selectAllCount();
		   int count=(int)UnitService.selectCount(ming);
		   int begin=0;
		   if(scount>count)
		   {			   
			   begin=count;
		   }
		   else{
			   extData.setTotalCount(0);
			   return extData;
		   }
		   System.out.println(scount+"总数据量");
			   sBaseGoodsUnit sInfo =new sBaseGoodsUnit();
			   BsData bsdata=new BsData();
			   bsdata.setBegin(begin);
			   bsdata.setLimit(scount);
			   sInfo.setBsData(bsdata);
			   List<BaseGoodsUnit> list=sUnitService.selectAllInfo(sInfo);
			   for(int j=0;j<list.size();j++)
			   {
				   BaseGoodsUnit info=list.get(j);
				   System.out.println(list.get(j).getUnitName());
				   info.setSmId(ming);			   				   
				  try
				   {
					  UnitService.insertSelective(info);					   
				   }
				   catch(Exception e){
					   System.out.println(info.getId()+"@@@@@");
					   extData.setTotalCount(j);
					   return extData;   
				   }
				   
			   }
			     			   
		   extData.setTotalCount(scount-count);	
	               
			return extData;    
		}

}
